]> git.r.bdr.sh - rbdr/map/blame - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
Add license notices
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
CommitLineData
98f09799
RBR
1/*
2 Copyright (C) 2024 Rubén Beltrán del Río
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
16 */
77d0155b 17import Combine
5e8ff485
RBR
18import CoreData
19import CoreGraphics
20import SwiftUI
21
22struct MapRenderView: View {
23
e2c37ac1 24 @Binding var document: MapDocument
fdb4633d 25 @Binding var evolution: StageType
e2c37ac1 26
fdb4633d
RBR
27 var stage: Stage {
28 Stage.stages(evolution)
29 }
75a0e450 30
e2c37ac1
RBR
31 var parsedMap: ParsedMap {
32 MapParser.parse(content: document.text)
33 }
5e8ff485 34
e2c37ac1
RBR
35 let mapSize = Dimensions.mapSize
36 let padding = Dimensions.mapPadding
5e8ff485 37
fdb4633d 38 let lineWidth = CGFloat(0.5)
5e8ff485 39 let vertexSize = CGSize(width: 25.0, height: 25.0)
e2c37ac1
RBR
40
41 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
5e8ff485 42
5e8ff485
RBR
43 var body: some View {
44 ZStack(alignment: .topLeading) {
45
46 Path { path in
47 path.addRect(
48 CGRect(
49 x: -padding, y: -padding, width: mapSize.width + padding * 2,
77d0155b 50 height: mapSize.height + padding * 4))
fdb4633d 51 }.fill(.white)
5e8ff485
RBR
52
53 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
54 MapAxes(
fdb4633d
RBR
55 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
56 MapEdges(
57 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
58 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
e2c37ac1
RBR
59 MapVertices(
60 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
61 onDragVertex: onDragVertex)
5e8ff485
RBR
62 MapOpportunities(
63 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
64 opportunities: parsedMap.opportunities)
e2c37ac1
RBR
65 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
66 opaque: true
67 ).opacity(0.1)
fdb4633d
RBR
68 MapNotes(
69 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
e2c37ac1
RBR
70 }.offset(x: padding, y: padding).frame(
71 width: mapSize.width + 2 * padding,
77d0155b 72 height: mapSize.height + 2 * padding, alignment: .topLeading
e2c37ac1 73 )
5e8ff485
RBR
74 }
75}
76
e2c37ac1
RBR
77#Preview {
78 MapRenderView(
79 document: Binding.constant(MapDocument(text: "")),
80 evolution: Binding.constant(StageType.general)
81 )
5e8ff485 82}